﻿using Microsoft.AspNetCore.Mvc;
using Zhp.Api.Attributes;
using Zhp.Auth;
using Zhp.Auth.IService;
using Zhp.Auth.Model;
using Zhp.Model.Common;

namespace Zhp.Api.Controllers.Monitor
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiGroup(GroupName = ApiGroupEnum.Monitor)]
    [SeedMenu(MenuGroup = ApiGroupEnum.Monitor, Name = "在线用户", Order = 5, RouterName = "onlineuser", WebFilePath = "monitor/onlineUser/index", Icon = "online-user")]
    public class OnlineController : ControllerBase
    {
        private readonly IOnlineService onlineSvc;

        public OnlineController(IOnlineService onlineService)
        {
            onlineSvc = onlineService;
        }

        [AllowOnline]
        [SeedList("在线用户列表", "在线用户", ApiGroupEnum.Monitor)]
        [HttpPost]
        public PageRet<OnlineUserViewModel> GetOnlineUserList(OnlineUserQuery query)
        {
            var list = onlineSvc.GetOnlineUserList(query);
            return new PageRet<OnlineUserViewModel>
            {
                DataList = list,
                TotalCount = list.Count,
            };
        }

        [SeedButton("强退", "在线用户列表", "在线用户", ApiGroupEnum.Monitor)]
        [HttpDelete("{cahceId}")]
        public bool Logout(string cahceId)
        {
            onlineSvc.ForcedRemoveOfflineUser(cahceId);

            return true;
        }

        [AllowOnline]
        [HttpGet]
        public PageRet<OnlineUserModel> GetOnlineActiveUserList()
        {
            var list = onlineSvc.GetOnlineActiveUserList();
            return new PageRet<OnlineUserModel>
            {
                DataList = list,
                TotalCount = list.Count,
            };
        }
    }
}
